<template>
  <d2-container>
    <button @click="getRouters">获取路由</button>
    <input type="text" v-model="bol">
    <div> {{ getMsg }}</div>
    <br>
    <button @click="getMenu">获取菜单</button>
  </d2-container>
</template>

<script>
import api from '@/api'
import { frameInRoutes } from '@/router/routes'
import { uniqueId } from 'lodash'
export default {
  data () {
    return {
      bol: '',
      msg: ''
    }
  },
  computed: {
    getMsg () {
      return this.msg
    }
  },
  watch: {
    bol () {
      this.jsp()
    }
  },
  created () {
    // this.getMenu()
  },
  methods: {
    async getMenu () {
      const res = await api.MENU_CURRENT()
      // api.MENU_CURRENT().then(res => console.log(res))
      console.log(Array.from(res))
      console.log(res)
      console.log(this.supplementPath(res))
    },
    async getRouters () {
      const files = require.context('@/router/modules', true, /\.js$/)

      const generators = files.keys().map(key => files(key).default)
      const res = this.$store.getters['d2admin/router/getRoutes']
      console.log('----frameInRoutes')
      // console.log(frameInRoutes)
      console.log('----res')
      console.log(res)
      // console.log(JSON.parse(JSON.stringify(res)))
    },
    async jsp () {
      console.log(!!this.bol)
      if (this.bol) {
        this.msg = '!this.if'
      }
    },
    supplementPath (menu) {
      return menu.map(e => ({
        ...e,
        path: e.path || uniqueId('d2-menu-empty-'),
        ...e.children ? {
          children: this.supplementPath(e.children)
        } : {}
      }))
    }
  }

}
</script>

<style>

</style>
